﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_ProTypeRefDescripttion.cs
* 创建标识：曾乃强 15158756652 2011-04-01 10:04:13
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_ProTypeRefDescripttion*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_ProTypeRefDescripttion
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_ProTypeRefDescripttion obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "ProTypeRefDescripttion ([ProductTypeID],[DescripttionName])");
            sql.Append("values(@ProductTypeID,@DescripttionName)");
            sql.Append(";SELECT @@IDENTITY");
            SqlParameter[] pra = {
                            new SqlParameter("@ProductTypeID",obj.ProductTypeID),
							new SqlParameter("@DescripttionName",obj.DescripttionName)
                                 };
            return Convert.ToInt32(DbHelper.ExecuteScalar(sql.ToString(), pra));
        }

        public int Update(Model.CNVP_ProTypeRefDescripttion obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "ProTypeRefDescripttion set [ProductTypeID] = @ProductTypeID,[DescripttionName] = @DescripttionName where [ID] = @ID");

            SqlParameter[] pra = { 
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@ProductTypeID",obj.ProductTypeID),
							new SqlParameter("@DescripttionName",obj.DescripttionName)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public int Delete(Model.CNVP_ProTypeRefDescripttion obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "ProTypeRefDescripttion where [ID] = @ID");
           SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public Model.CNVP_ProTypeRefDescripttion LoadById(int ID)
        {

            StringBuilder sql = new StringBuilder();
            sql.Append("select [ProductTypeID],[DescripttionName] from " + Prefix + "ProTypeRefDescripttion");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(), pra);
            Model.CNVP_ProTypeRefDescripttion cnvp_protyperefdescripttion = new Model.CNVP_ProTypeRefDescripttion();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_protyperefdescripttion.ProductTypeID = dr["ProductTypeID"] is DBNull ? 0 : (int)dr["ProductTypeID"];
                cnvp_protyperefdescripttion.DescripttionName = dr["DescripttionName"] is DBNull ? String.Empty : (string)dr["DescripttionName"];
            }
            return cnvp_protyperefdescripttion;
        }

        #endregion

        public List<Model.CNVP_ProTypeRefDescripttion> LoadAll(int ProductTypeID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[DescripttionName] from " + Prefix + "ProTypeRefDescripttion");
            sql.Append(" where [ProductTypeID] = @ProductTypeID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProductTypeID",ProductTypeID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(), pra);
            List<Model.CNVP_ProTypeRefDescripttion> list = new List<Model.CNVP_ProTypeRefDescripttion>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_ProTypeRefDescripttion cnvp_protyperefdescripttion = new Model.CNVP_ProTypeRefDescripttion();
                    cnvp_protyperefdescripttion.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_protyperefdescripttion.DescripttionName = dr["DescripttionName"] is DBNull ? String.Empty : (string)dr["DescripttionName"];
                    list.Add(cnvp_protyperefdescripttion);
                }
            }
            return list;

        }

        public int DeleteNotIn(int ProductTypeID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "ProTypeRefDescripttion where [ProductTypeID]=" + ProductTypeID + " and [ID] not in (" + nowid + ")");
            return DbHelper.ExecuteNonQuery(sql.ToString());
        }
    }
}

